#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int n;
	while (cin >> n)
	{
		int m = log(n + 1) / log(2);
		cout << ((1 << m) - 1) << endl;
	}
	return 0;
}